<template>
  <div class="password">
    <van-nav-bar title="修改交易密码" left-arrow @click-left="goBack"></van-nav-bar>
    <div class="content">
      <section>
        <van-field v-model="originalPassword" label="交易密码" placeholder="请输入原交易密码"/>
        <van-field v-model="newPassword" label="新密码" placeholder="密码由6位数字组成"/>
        <van-field v-model="confirmPassword" label="确认新密码" placeholder="请再次输入新密码"/>
      </section>
      <div class="login-out">
        <button type="submit" class="submit-btn" @click="modifyPassword">确认</button>
      </div>
    </div>
  </div>
</template>
<script>
import Vue from "vue";
import axios from "axios";
import { updatePassword } from "../../../axios/api.js";
import { NavBar, Field,Toast } from "vant";
export default {
  components: {
    [NavBar.name]: NavBar,
    [Field.name]: Field,
    [Toast.name]: Toast
  },
  data() {
    return {
      token: "",
      originalPassword: "",
      newPassword: "",
      confirmPassword: ""
    };
  },
  methods: {
    //返回上一页
    goBack() {
      this.$router.go(-1);
    },
    //修改交易密码
    modifyPassword() {
      var that = this;
      console.log(that.originalPassword)
     var reg = /^\d{6}$/; 
     if(!reg.test(that.originalPassword)){  
        Toast('请输入正确的交易密码')  
        return false;
    }  
    $.ajax({
        type:'post',
        url:window.nowHref + "/user/updatePassword",
        dataType:'json',
        data:{
             token:localStorage.getItem('setToken'),
             originalPassword:that.originalPassword,
             newPassword :that.newPassword,
             confirmPassword :that.confirmPassword,
             type:0,
             passwordType:1
        },
        success:function(data){
            console.log(data)
            if(data.code == 228){
                Toast(data.msg)
            }
            if(data.code == 200){
                Toast("修改成功！")
                that.$router.push({name: "passwordSetting"});
            }
        }
    })
    }
  }
};
</script>
<style lang="less" scoped>
@import "../../../assets/less/variable.less";
/deep/.van-cell__title {
  text-align: left;
}
/deep/.van-cell::after {
  content: " ";
  position: absolute;
  pointer-events: none;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  left: 0;
  right: 0;
  bottom: 0;
  -webkit-transform: scaleY(0.5);
  transform: scaleY(0.5);
  border-bottom: 1px solid #ebedf0;
}
//18685214587
.password {
  background: #fff;
  .content {
    background: #fff;
    .login-out {
      margin-top: 0.67rem;
      width: 100%;
      background-color: #fff;
      color: #fff;
      font-size: @base_textSize;
      .submit-btn {
        width: 85%;
        height: 34px;
        text-align: center;
        line-height: 34px;
        font-size: 14px;
        background-color: #d6ab6f;
        color: white;
        border-radius: 20px;
        margin: 10vh auto 0;
        border: 0;
      }
    }
  }
}
</style>